package com.top.ruizhong.popup

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.ScaleAnimation
import android.view.animation.TranslateAnimation
import android.widget.TextView
import com.blankj.utilcode.util.*
import com.top.ruizhong.R
import razerdp.basepopup.BasePopupWindow


class GoodsScreenPopup(
    context: Context, val onConfirm: () -> Unit
) : BasePopupWindow(context) {

    override fun onCreateContentView(): View {
        return createPopupById(R.layout.popup_goods_screen)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)

        contentView.findViewById<TextView>(R.id.tvScreenPopupReset).setOnClickListener {
            onConfirm()
        }
        contentView.findViewById<TextView>(R.id.tvScreenPopupComplete).setOnClickListener {
            this.dismiss()
        }
        contentView.setOnClickListener {
            dismiss()
        }
    }


//    override fun onCreateShowAnimation(width: Int, height: Int): Animation {
//        val showAnimation: Animation = ScaleAnimation(1f, 1f, 0f, 1f)
//        showAnimation.duration = 400
//        return showAnimation
//    }
//
//    override fun onCreateDismissAnimation(): Animation {
//        val showAnimation: Animation = ScaleAnimation(1f, 1f, 1f, 0f)
//        showAnimation.duration = 400
//        return showAnimation
//    }

    fun setFillData(view: View) {


        isOutSideTouchable = true
        setBackground(0)
        setPopupGravity(GravityMode.RELATIVE_TO_ANCHOR, Gravity.BOTTOM)
        setOverlayNavigationBar(false)

        val intArray = IntArray(2)
        view.getLocationOnScreen(intArray)
        val viewHeight: Int = ConvertUtils.px2dp(view.height.toFloat())
        height = ScreenUtils.getAppScreenHeight() - intArray[1] - viewHeight
    }
}